package com.cheifsteam.springframework.core.io;

import java.net.MalformedURLException;
import java.net.URL;

/**
 * @author 屈燃希
 * @date 2025/1/23 17:32
 * @content
 */
public class DefaultResourceLoader implements ResourceLoader{
    @Override
    public Resource getResource(String location) {
        if (location.startsWith(CLASSPATH_PREFIX)){
            return new ClassPathResource(location.substring(CLASSPATH_PREFIX.length()));
        }
        else {
            try {
                URL url = new URL(location);
                return new UrlResource(url);
            } catch (MalformedURLException e) {
                return new FileSystemResource(location);
            }
        }


    }
}
